package org.linlinjava.litemall.core.util;

import org.linlinjava.litemall.core.systemConfig.GetRegionService;
import org.linlinjava.litemall.db.domain.LitemallMechanism;
import org.linlinjava.litemall.db.domain.LitemallRegion;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 将地址id转成正式地址
 *
 * @author zhy
 * @date 2019-01-28 14:36
 **/
@Service
public class LitemallMechanismToVo extends GetRegionService {

	public Map<String, Object> toVo(LitemallMechanism mdList) {
		List<LitemallRegion> regionList = getLitemallRegions();
		Map<String, Object> addressVo = new HashMap<>();
		String province = "";
		String city = "";
		String area = "";
		addressVo.put("id", mdList.getId());
		addressVo.put("name", mdList.getName());
		addressVo.put("nickName", mdList.getNickName());
		addressVo.put("mechanismType", mdList.getMechanismType());
		if (mdList.getProvinceId() != null) {
			addressVo.put("provinceId", mdList.getProvinceId());
			province = regionList.stream().filter(region -> region.getId().equals(mdList.getProvinceId())).findAny().orElse(null).getName();
		}
		if (mdList.getCityId() != null) {
			addressVo.put("cityId", mdList.getCityId());
			city = regionList.stream().filter(region -> region.getId().equals(mdList.getCityId())).findAny().orElse(null).getName();
		}
		if (mdList.getAreaId() != null) {
			addressVo.put("areaId", mdList.getAreaId());
			area = regionList.stream().filter(region -> region.getId().equals(mdList.getAreaId())).findAny().orElse(null).getName();
		}
		if (mdList.getAddress() != null) {
			addressVo.put("address", mdList.getAddress());
			addressVo.put("allAdderss", province + city + area + "" + mdList.getAddress());
		}
		addressVo.put("legalPerson", mdList.getLegalPerson());
		addressVo.put("telephone", mdList.getTelephone());
		addressVo.put("startTime", mdList.getStartTime());
		addressVo.put("endTime", mdList.getEndTime());
		addressVo.put("qualifications", mdList.getQualifications());
		addressVo.put("integralAmountAll", mdList.getIntegralAmountAll());
		addressVo.put("integralAmountUsed", mdList.getIntegralAmountUsed());
		addressVo.put("updateTime", mdList.getUpdateTime());
		addressVo.put("deleted", mdList.getDeleted());
		addressVo.put("province", province);
		addressVo.put("city", city);
		addressVo.put("area", area);
		addressVo.put("longitude", mdList.getLongitude());
		addressVo.put("latitude", mdList.getLatitude());
		addressVo.put("mcategoryId", mdList.getMcategoryId());
		addressVo.put("level", mdList.getLevel());
		addressVo.put("checkStatus", mdList.getCheckStatus());
		addressVo.put("alpay", mdList.getAlpay());
		addressVo.put("wechat", mdList.getWechat());
		addressVo.put("certification", mdList.getCertification());


		return addressVo;
	}
}
